package com.getpebble.android.framework.protocol.inbound;

import com.getpebble.android.bluetooth.protocol.ProtocolMessage;
import com.getpebble.android.framework.protocol.inbound.PblInboundAppInstallMessage.AppInstallResponseType;
import java.nio.ByteBuffer;

public class PblInboundAppResultInstallMessage extends PblInboundAppInstallMessage {
    private int mResultCode;

    public enum AppAvailResult {
        SUCCESS(1),
        BANK_IN_USE(2),
        INVALID_COMMAND(3),
        GENERAL_FAILURE(4),
        SDK_INCOMPATIBLE(5),
        INVALID_UUID(6),
        UUID_CONFLICT(7);
        
        private final int id;

        private AppAvailResult(int id) {
            this.id = id;
        }

        public static AppAvailResult fromKey(int i) {
            for (AppAvailResult code : values()) {
                if (code.id == i) {
                    return code;
                }
            }
            return GENERAL_FAILURE;
        }
    }

    public enum AppRemoveResult {
        SUCCESS(1),
        NO_APP_IN_BANK(2),
        INSTALL_ID_MISMATCH(3),
        INVALID_COMMAND(4),
        GENERAL_FAILURE(5),
        INVALID_UUID(6),
        IN_PRF(7),
        TIMEOUT(8),
        NOT_CONNECTED(9);
        
        private final int id;

        private AppRemoveResult(int id) {
            this.id = id;
        }

        public static AppRemoveResult fromKey(int i) {
            for (AppRemoveResult code : values()) {
                if (code.id == i) {
                    return code;
                }
            }
            return GENERAL_FAILURE;
        }

        public int getId() {
            return this.id;
        }
    }

    public enum AppUpgradeResult {
        SUCCESS(1),
        NO_APP_IN_BANK(2),
        INSTALL_ID_MISMATCH(3),
        INVALID_COMMAND(4),
        GENERAL_FAILURE(5),
        INVALID_UUID(6);
        
        private final int id;

        private AppUpgradeResult(int id) {
            this.id = id;
        }

        public static AppUpgradeResult fromKey(int i) {
            for (AppUpgradeResult code : values()) {
                if (code.id == i) {
                    return code;
                }
            }
            return GENERAL_FAILURE;
        }
    }

    public PblInboundAppResultInstallMessage(ProtocolMessage message) {
        super(message);
        ByteBuffer buffer = message.getDataBuffer();
        checkResponseType(buffer.get());
        this.mResultCode = buffer.getInt();
    }

    public AppRemoveResult getResultAsRemove() {
        return AppRemoveResult.fromKey(this.mResultCode);
    }

    public AppUpgradeResult getResultAsUpgrade() {
        return AppUpgradeResult.fromKey(this.mResultCode);
    }

    public AppAvailResult getResultAsAvail() {
        return AppAvailResult.fromKey(this.mResultCode);
    }

    public AppInstallResponseType getResponseType() {
        return AppInstallResponseType.APP_RESULT;
    }

    protected int getMinSize() {
        return 5;
    }
}
